<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<html lang="zh-cn">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>系统参数列表</title>
    <jsp:include page="../common/common.jsp"/>
    <style>
        .searchs{
            padding-top: 20px;
        }
        .w-45p{
            width:45%!important;
        }
        .w-10p{
            width: 10%!important;
            text-align: center;
            line-height: 34px;
        }
        .w-50{
            width:60px!important;
        }
        table{
    		font-size:small;
    		table-Layout:fixed;
    	}
        th{
        	font-size:small;
        }
        .control-p{
      	    line-height:  22px;
        	padding: 0 6px;
        	font-size: 14px;
        }
        .control-p>font{
        	width: 100px;
        	float: left;
        }
        .control-p>span{
        	width: 430px;
        	float: left;
        }
    </style>
</head>
<body>

<div id="main">
    <div class="searchs">
        <form method="post" class="form-horizontal searchsForm">
            <div class="col-lg-4 col-md-4 form-group">
                <label class="col-lg-3 col-md-3 control-label">键名称</label>
                <div class="col-lg-8 col-md-8">
                    <input type="text" class="form-control" name="keyName" id="keyName"/>
                </div>
            </div>
            <div class="col-lg-4 col-md-4 form-group">
                <label class="col-lg-3 col-md-3 control-label">创建时间</label>
                <div class="col-lg-8 col-md-8 clearfix">
                    <input class="w-45p form-control fl form_datetime" name="startCreateTime" id="startCreateTime" type="text" readonly>
                    <span class="w-10p fl">—</span>
                    <input class="w-45p form-control fl form_datetime" name="endCreateTime" id="endCreateTime" type="text" readonly>
                </div>
            </div>
            <div class="col-lg-4 col-md-4 form-group">
                <label class="col-lg-3 col-md-3 control-label">修改时间</label>
                <div class="col-lg-8 col-md-8 clearfix">
                    <input class="w-45p form-control fl form_datetime" name="startUpdateTime" id="startUpdateTime" type="text" readonly>
                    <span class="w-10p fl">—</span>
                    <input class="w-45p form-control fl form_datetime" name="endUpdateTime" id="endUpdateTime" type="text" readonly>
                </div>
            </div>
            <div class="col-lg-4 col-md-4 form-group">
                <label class="col-lg-3 col-md-3 control-label">创建人</label>
                <div class="col-lg-8 col-md-8">
                    <input type="text" class="form-control" name="opUser" id="opUser"/>
                </div>
            </div>
            <div class="col-lg-4 col-md-4 form-group">
                <label class="col-lg-3 col-md-3 control-label">是否启用</label>
                <div class="col-lg-8 col-md-8">
					<select class="form-control" id="isUse" name="isUse">
                        <option value="">---请选择---</option>
						<option value="1">启用</option>
						<option value="2">不启用</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <div class="col-lg-3 col-md-3 col-lg-offset-9 col-md-offset-9">
                    <button id="search" type="button" class="btn btn-primary w-50 fr" style="margin-left: 10px; margin-right: 10px;">搜索</button>
                    <input type="reset" id="reset" class="btn btn-primary w-50 fr btn-reset" value="重置">
                </div>
            </div>
        </form>
    </div>
    <div id="toolbar">
        <a class="waves-effect waves-button" href="${webroot}/admin/page/sysparams/sysParamsAdd"><i class="glyphicon glyphicon-plus"></i>添加</a>
        <a class="waves-effect waves-button" href="javascript:;" onclick="deleteAction()"><i class="glyphicon glyphicon-remove"></i>删除</a>
    </div>

    <table id="table"></table>
</div>

<script>
    var $table = $('#table');
    var totalSize;
    $(function() {
        /* var roleId = $('#roleId option:selected').val(); */
        /* var loginName = $('#loginName').val(); */
        $(document).on('focus', 'input[type="text"]', function() {
            $(this).parent().find('label').addClass('active');
        }).on('blur', 'input[type="text"]', function() {
            if ($(this).val() == '') {
                $(this).parent().find('label').removeClass('active');
            }
        });
        // 数据格式[json]必须包含：total节点（总记录数），rows节点（分页后数据）
        //即：{“total”:24,”rows”:[…]}
        $table.bootstrapTable({
            url: webroot+'/admin/sysparams/queryListSysParamsData',
            height: getHeight(),
            striped: true,
            minimumCountColumns: 2,
            clickToSelect: true,
            responseHandler:function(res){
            	totalSize = res.total
            	return res;
            },
			showExport: false,  //是否显示导出按钮 
			exportDataType:'all',
       		exportTypes:['excel'],  //导出文件类型
         	exportOptions:{
			ignoreColumn: [0,11],  //忽略某一列的索引  
            fileName: '系统参数表',  //文件名称设置  
            worksheetName: 'sheet1',  //表格工作区名称  
            tableName: '系统参数表',  
            excelstyles: ['background-color', 'color', 'font-size', 'font-weight'],  
         },
            pagination: true,
            paginationLoop: false,
            pageList:[10,20,30,40,50],
            classes: 'table table-hover table-no-bordered',
            // 服务端分页
            sidePagination: 'server',
		 	queryParams:function(params) {
				var pageNum = (params.offset+1==1?1:((params.offset-(params.limit))/10+2));
				var numPerPage = params.limit;
				if(isNaN(pageNum)){pageNum="";
			}
			if(typeof(numPerPage)=="undefined"){
				numPerPage=totalSize;
			}
            var keyName = $('#keyName').val();
            var startCreateTime = $('#startCreateTime').val();
            var endCreateTime = $('#endCreateTime').val();
            var startUpdateTime = $('#startUpdateTime').val();
            var endUpdateTime = $('#endUpdateTime').val();
            var opUser = $('#opUser').val();
            var isUse = $('#isUse option:selected').val();
            
            return {//此处添加查询的分页条件
            pageNum:pageNum,
            numPerPage: numPerPage,
            keyName : keyName,
            startCreateTime:startCreateTime,
            endCreateTime:endCreateTime,
            startUpdateTime:startUpdateTime,
            endUpdateTime:endUpdateTime,
            opUser : opUser,
            isUse : isUse
          };
		 },
            smartDisplay: false,
            idField: 'id',
            // 关闭排序
            sortable: false,
            escape: true,
            idField: 'systemId',
            maintainSelected: true,
            toolbar: '#toolbar',
            columns: [
                // field： 对应数据字段
                // title： 标题内容
                // sortable： 是否开启排序
                // halign : 内容垂直居中
                //formatter : 通过formatter可以自定义列显示的内容
                //value：当前field的值，即id
                //row：当前行的数据
                {field: 'state', checkbox: true},
                {field: 'id', title: 'id', visible: false, align: 'center'},
                {field: '', title:'序号',sortable: true, align: 'center',formatter:function (value, row, index) { return index+1;  }  },
                {field: 'keyName', title: '键名称', sortable: true, align: 'center'},
                {field: 'keyEname', title: '键英文名称', sortable: true, align: 'center'},
                {field: 'keyValue', title: '键值',width:'40%',sortable: true, align: 'center'},
                {field: 'createTime', title: '创建时间', sortable: true, align: 'center',formatter:'getCreateTimeFormatterTime'},
                {field: 'updateTime', title: '修改时间', sortable: true, align: 'center',formatter:'getCreateTimeFormatterTime'},
                {field: 'opUser', title: '操作人', sortable: true, align: 'center'},
                {field: 'status', title: '是否启用', sortable: true, align: 'center',formatter:'formatIsUse'},
                {field: 'remark', title: '备注', sortable: true, align: 'center'},
                {field: 'action', title: '操作', halign: 'center', align: 'center', formatter: 'actionFormatter', events: 'actionEvents', clickToSelect: false}
            ]
        }).on('all.bs.table', function (e, name, args) {
            $('[data-toggle="tooltip"]').tooltip();
            $('[data-toggle="popover"]').popover();
        });
    });
    //格式化数据
    function formatIsUse(value, row, index) {
    	var ns = value;
    	if(undefined == ns || null == ns){
    		return "";
    	}
    	return value == 0 ? '否' : '是';
    }
    
  	//格式化a标签
    function actionFormatter(value, row, index) {
        return [
                '<a class="edit ml10" href="${webroot}/admin/page/sysparams/sysParamsUpdate?sysParamsId='+row.id+'" data-toggle="tooltip" title="编辑"><i class="glyphicon glyphicon-edit"></i></a>　'
        ].join('');
    }
  	
 	// 删除
    function deleteAction() {
        var rows = $table.bootstrapTable('getSelections');
        if (rows.length == 0) {
            $.confirm({
                title: false,
                content: '请至少选择一条记录！',
                autoClose: 'cancel|3000',
                backgroundDismiss: true,
                buttons: {
                    cancel: {
                        text: '取消',
                        btnClass: 'waves-effect waves-button'
                    }
                }
            });
        } else {
            $.confirm({
                type: 'red',
                animationSpeed: 300,
                title: false,
                content: '确认删除吗？',
                buttons: {
                    confirm: {
                        text: '确认',
                        btnClass: 'waves-effect waves-button',
                        action: function () {
                            // 删除确定，执行数据操作
                            var ids = "";
                            for (var i in rows) {
                            	ids += rows[i].id +",";
                            }
                            $.ajax({
                                type:'post',
                                url:webroot+'/admin/sysparams/batchdeletedata',
                                data:{"ids":ids},
                                async:false,
                                dataType:'json',
                                success:function(data){
                                	checkResponseData(data, "1", webroot+'/admin/page/sysparams/sysParamsList');
                                },
                                error:function(){
                                    alert("请求出错啦！");
                                }
                            });
                        }
                    },
                    cancel: {
                        text: '取消',
                        btnClass: 'waves-effect waves-button'
                    }
                }
            });
        }
    }
    
    //条件查询 使用refresh来更新tableb表格
     $('#search').click(function () {
            $table.bootstrapTable('refresh', {url: webroot+'/admin/sysparams/queryListSysParamsData'});
    });
   
    $(".form_datetime").datetimepicker({
        //时间格式
        format: 'yyyy-mm-dd hh:ii:ss',
        language: 'zh-CN',
        autoclose:true,
        minView:0,
        todayBtn:true
    });
    
</script>
</body>
</html>
